#include <stdio.h>
#include <stdlib.h>

typedef struct node
{
    int data;
    struct node* next;
}LNode;
void Slistpushhead(LNode** phead,int x)
{
    LNode* newnode;
    newnode=(LNode*)malloc(sizeof(LNode));
    newnode->data=x;
    newnode->next=*phead;
    *phead=newnode;
}
int main()
{
    int x;
    LNode *plist;
    plist=NULL;
    while(scanf("%d",&x),x>0)
    {
        Slistpushhead(&plist,x);
    }
    if(plist==NULL)
    {
        printf("Node not found!\n");
        return 0;
    }
    int v;
    scanf("%d %d",&x,&v);
    LNode* cur;
    cur=(LNode*)malloc(sizeof(LNode));
    cur=plist;
    int f=0;
    if(x==1)
    {
        plist->data=v;
    }
    else
    {
        for(int i=1;i<x;i++)
        {

            cur=cur->next;
            if(cur==NULL)
            {
                f=1;
                break;
            }
        }
        if(f==0)
        {
            cur->data=v;
        }
    }
    cur=plist;
    while(cur!=NULL)
    {
        printf("%d ",cur->data);
        cur=cur->next;
    }
    return 0;
}
